using System.Collections.Generic;
using System.Xml;

namespace NGIS.Model
{
	public class LocalizationHelper
	{
		public static string LocalizationType2String(ELocalizationType pType)
		{
			switch (pType)
			{
			case ELocalizationType.ELT_ZH_CN:
				return "ZH_CN";
			case ELocalizationType.ELT_EN_US:
				return "EN_US";
			case ELocalizationType.ELT_DE_DE:
				return "DE_DE";
			case ELocalizationType.ELT_RU_RU:
				return "RU_RU";
			case ELocalizationType.ELT_AR:
				return "AR";
			case ELocalizationType.ELT_ES:
				return "ES";
			default:
				return "Unknown";
			}
		}

		public static ELocalizationType String2LocalizationType(string pTypeStr)
		{
			if (pTypeStr == "ZH_CN")
			{
				return ELocalizationType.ELT_ZH_CN;
			}
			if (pTypeStr == "EN_US")
			{
				return ELocalizationType.ELT_EN_US;
			}
			if (pTypeStr == "DE_DE")
			{
				return ELocalizationType.ELT_DE_DE;
			}
			if (pTypeStr == "RU_RU")
			{
				return ELocalizationType.ELT_RU_RU;
			}
			if (pTypeStr == "AR")
			{
				return ELocalizationType.ELT_AR;
			}
			if (pTypeStr == "ES")
			{
				return ELocalizationType.ELT_ES;
			}
			return ELocalizationType.ELT_COUNT;
		}

		public static string MechanismType2String(EMechanismItemType mType)
		{
			switch (mType)
			{
			case EMechanismItemType.EMIT_Algorithm:
				return "Algorithm";
			case EMechanismItemType.EMIT_Formula:
				return "Formula";
			case EMechanismItemType.EMIT_Text:
				return "Text";
			default:
				return "Unknown";
			}
		}

		public static EMechanismItemType String2MechanismItemType(string sType)
		{
			if (sType == "Algorithm")
			{
				return EMechanismItemType.EMIT_Algorithm;
			}
			if (sType == "Formula")
			{
				return EMechanismItemType.EMIT_Formula;
			}
			if (sType == "Text")
			{
				return EMechanismItemType.EMIT_Text;
			}
			return EMechanismItemType.EMIT_Unknown;
		}

		public static string SpatiotemporalScaleType2String(ESpatiotemporalScaleType ssType)
		{
			switch (ssType)
			{
			case ESpatiotemporalScaleType.EMSST_Global:
				return "Global";
			case ESpatiotemporalScaleType.EMSST_Region_Large:
				return "Region";
			case ESpatiotemporalScaleType.EMSST_Region_Middle:
				return "Region";
			case ESpatiotemporalScaleType.EMSST_Region_Small:
				return "Region";
			default:
				return "Unknown";
			}
		}

		public static string SpatiotemporalScale2String(ESpatiotemporalScaleType ssType)
		{
			switch (ssType)
			{
			case ESpatiotemporalScaleType.EMSST_Global:
				return "";
			case ESpatiotemporalScaleType.EMSST_Region_Large:
				return "Large";
			case ESpatiotemporalScaleType.EMSST_Region_Middle:
				return "Middle";
			case ESpatiotemporalScaleType.EMSST_Region_Small:
				return "Small";
			default:
				return "Unknown";
			}
		}

		public static ESpatiotemporalScaleType String2SpatiotemporalScaleType(string sType, string sScale)
		{
			if (sType == "Global")
			{
				return ESpatiotemporalScaleType.EMSST_Global;
			}
			if (sType == "Regional" && sScale == "Large")
			{
				return ESpatiotemporalScaleType.EMSST_Region_Large;
			}
			if (sType == "Regional" && sScale == "Middle")
			{
				return ESpatiotemporalScaleType.EMSST_Region_Middle;
			}
			if (sType == "Regional" && sScale == "Small")
			{
				return ESpatiotemporalScaleType.EMSST_Region_Small;
			}
			return ESpatiotemporalScaleType.EMSST_Unknown;
		}

		public static EContactType String2ContactType(string sContact)
		{
			if (sContact == "Email")
			{
				return EContactType.ECT_Email;
			}
			if (sContact == "Fax")
			{
				return EContactType.ECT_Fax;
			}
			if (sContact == "Phone")
			{
				return EContactType.ECT_Phone;
			}
			return EContactType.ECT_Unknown;
		}

		public static string ContactType2String(EContactType eContact)
		{
			switch (eContact)
			{
			case EContactType.ECT_Email:
				return "Email";
			case EContactType.ECT_Fax:
				return "Fax";
			case EContactType.ECT_Phone:
				return "Phone";
			default:
				return "Unknown";
			}
		}

		public static List<ModelUser> Xml2ModelUser(XmlElement mele)
		{
			List<ModelUser> list = new List<ModelUser>();
			foreach (XmlElement childNode in mele.ChildNodes)
			{
				string attribute = childNode.GetAttribute("name");
				string attribute2 = childNode.GetAttribute("account");
				XmlElement xmlElement2 = (XmlElement)mele.ChildNodes[0];
				string attribute3 = childNode.GetAttribute("name");
				string attribute4 = childNode.GetAttribute("country");
				string attribute5 = childNode.GetAttribute("city");
				string attribute6 = childNode.GetAttribute("address");
				ModelUserInstitution ins = new ModelUserInstitution(attribute3, attribute4, attribute5, attribute6);
				XmlElement xmlElement3 = (XmlElement)mele.ChildNodes[0];
				List<ModelUserContact> list2 = new List<ModelUserContact>();
				foreach (XmlElement childNode2 in xmlElement3.ChildNodes)
				{
					string attribute7 = childNode2.GetAttribute("type");
					string attribute8 = childNode2.GetAttribute("value");
					list2.Add(new ModelUserContact(String2ContactType(attribute7), attribute8));
				}
				ModelUser item = new ModelUser(attribute, attribute2, ins, list2);
				list.Add(item);
			}
			return list;
		}
	}
}
